#!/bin/sh

if [ "$(grep envID /proc/self/status)" == "" ] ; then
	if [ "$(rpm -qa|grep kexec-tools)" == "" ] ; then
		yum install kexec-tools -y
	fi

	latestkernel=$(ls -t /boot/vmlinuz-* | sed "s/\/boot\/vmlinuz-//g" | head -n1)

	if [ -f /boot/initrd-${latestkernel}.img ] ; then
		imgfile="/boot/initrd-${latestkernel}.img"
	elif [ -f /boot/initrd-${latestkernel}kdump.img ] ; then
		imgfile="/boot/initrd-${latestkernel}kdump.img"
	else
		imgfile="/boot/initramfs-${latestkernel}.img"
	fi

	kexec -l /boot/vmlinuz-${latestkernel} --initrd=${imgfile} --append="$(cat /proc/cmdline)"
	kexec -e
else
	echo 'Not work in OpenVZ container'
fi